package com.thomasmoerman.dci2.app

import com.thomasmoerman.dci2.domain._
import com.thomasmoerman.dci2.registry._
import com.thomasmoerman.dci2.tmc._
import com.thomasmoerman.dci2.pbc._

object PayBillsContextTestApp
  extends PayBillsRegistry
     with TransactionalDataAccessRegistry
     with MyDataSource {

  def main(args: Array[String]) {
	insertTestData

    val james = inTransaction(findPerson("James"))
  
    new PayBillsContext(james).execute
  }
  
  def insertTestData {
    inTransaction {
      drop
      create
    	
      val james = persons.insert(new Person(firstName = "James", lastName = "Coplien", accountId = 1))
      val trygve = persons.insert(new Person(firstName = "Trygve", lastName = "Reenskaug", accountId = 2))
      val rickard = persons.insert(new Person(firstName = "Rickard", lastName = "Oberg", accountId = 3))

      bills.insert(new Bill(debtorId = james.id, creditorId = trygve.id, amount = 3, comment = "Sandwich"))
      bills.insert(new Bill(debtorId = james.id, creditorId = trygve.id, amount = 50, comment = "PowerPoint slides"))
      bills.insert(new Bill(debtorId = james.id, creditorId = rickard.id, amount = 100, comment = "Consultancy services"))
      
      moneyTransfers.insert(Increase(accountId = 1, amount = 200))
    }
  }

}